cmake_minimum_required(VERSION 3.10)
project(FilterProject C CXX)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)

# 编译器设置
if(WIN32)
    set(CMAKE_C_COMPILER gcc)
    set(CMAKE_CXX_COMPILER g++)
endif()

# GoogleTest配置
option(FETCH_GOOGLETEST "Fetch GoogleTest from GitHub" ON)
if(FETCH_GOOGLETEST)
    include(FetchContent)
    FetchContent_Declare(
        googletest
        GIT_REPOSITORY https://github.com/google/googletest.git
        GIT_TAG release-1.12.1
    )
    FetchContent_MakeAvailable(googletest)
endif()

# 包含目录
include_directories(src)

# 主库
add_library(filter_lib STATIC src/filter.c)

# 测试可执行文件
add_executable(filter_test 
    test/test_filter.c
    test/test_runner.c
    src/filter.c
)

target_link_libraries(filter_test gtest gtest_main)

# 启用测试
enable_testing()
add_test(NAME filter_unit_tests COMMAND filter_test)

# 安装规则
install(TARGETS filter_lib DESTINATION lib)
install(FILES src/filter.h DESTINATION include)